package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.bean.MyPage;
import com.serkol.ams.bean.MyPageOld;
import com.serkol.ams.entity.Shop;
import com.serkol.ams.service.ShopService;
import com.serkol.ams.mapper.ShopMapper;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author Administrator
* @description 针对表【shop】的数据库操作Service实现
* @createDate 2025-01-20 11:08:43
*/
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop>
    implements ShopService{

    @Override
    public MyPage<Map<String, Object>> findByList(int pageSize, int current) {
        MyLambdaQueryWrapper<Shop> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(Shop::getId, Shop::getName,Shop::getAddress,Shop::getRemark,Shop::getStatus).select(Shop::getNameUg).as("nameUg")
                .select(Shop::getLatitude).as("latitude").select(Shop::getLongitude).as("longitude").select(Shop::getPhoneNumber).as("phoneNumber")
                .select(Shop::getPostNumber).as("postNumber")
               .picture(Shop::getLogoId).as("logoUrl").select(Shop::getCreateDate).as("createDate").select(Shop::getUpdateDate).as("updateDate");

        queryWrapper.orderByDesc(Shop::getId,Shop::getCreateDate);
        Page<Map<String, Object>> page = new Page<>(current, pageSize);
        IPage<Map<String, Object>> data = this.baseMapper.selectMapsPage(page, queryWrapper);


        return MyPage.parsePage(data);
    }

    @Override
    public List<Map<String, Object>> miniList() {
        MyLambdaQueryWrapper<Shop> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(Shop::getId, Shop::getName,Shop::getAddress,Shop::getRemark,Shop::getStatus).select(Shop::getNameUg).as("nameUg")
                .select(Shop::getLatitude).as("latitude").select(Shop::getLongitude).as("longitude").select(Shop::getPhoneNumber).as("phoneNumber")
                .select(Shop::getPostNumber).as("postNumber")
                .picture(Shop::getLogoId).as("logoUrl").select(Shop::getCreateDate).as("createDate").select(Shop::getUpdateDate).as("updateDate");

        queryWrapper.orderByDesc(Shop::getId,Shop::getCreateDate);
        return this.baseMapper.selectMaps(queryWrapper);

    }

    @Override
    public Map<String, Object> findMapById(long id) {
        MyLambdaQueryWrapper<Shop> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(Shop::getId, Shop::getAddress,Shop::getRemark,Shop::getStatus).
                select(Shop::getLatitude).as("latitude").select(Shop::getLongitude).as("longitude").select(Shop::getPhoneNumber).as("phoneNumber")
                .select(Shop::getPostNumber).as("postNumber")
                .picture(Shop::getLogoId).as("logoUrl").langName(Shop::getName,Shop::getNameUg).as("name").select(Shop::getCreateDate).as("createDate").select(Shop::getUpdateDate).as("updateDate");

        queryWrapper.orderByDesc(Shop::getId,Shop::getCreateDate).last("limit 1");
        queryWrapper.eq(Shop::getId,id);
        return this.getMap(queryWrapper);
    }
}




